//
//  AppDelegate.h
//  Address-book📞
//
//  Created by Mars_ZXB on 16/8/6.
//  Copyright © 2016年 BAT3. All rights reserved.
//

#import "SandboxHandler.h"

@implementation SandboxHandler


+ (NSString *)pathForDocuments {
    return [SandboxHandler pathForDirectory:Documents WithFileName:nil];
}

+ (NSString *)pathForLibrary {
    return [SandboxHandler pathForDirectory:Library WithFileName:nil];

}

+ (NSString *)pathForTmp {
    return [SandboxHandler pathForDirectory:Tmp WithFileName:nil];
}

+ (NSString *)pathForCaches {
    return [SandboxHandler pathForDirectory:Caches WithFileName:nil];
}

// 核心代码
+ (NSString *)pathForDirectory:(SandboxDirectory)directory WithFileName:(NSString *)fileName {
    switch (directory) {
        case 0:{
            NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
            return [path stringByAppendingPathComponent:fileName];
        }
            break;
            
        case 1:
        {
            NSString *path = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
            return [path stringByAppendingPathComponent:fileName];
        }
            break;
        case 2:
        {
            NSString *path = NSTemporaryDirectory();
        
            return [path stringByAppendingPathComponent:fileName];
        }
            break;
        case 3: {
            NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
            return [path stringByAppendingPathComponent:fileName];
        }
            
            break;
    }

}




@end
